<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <title>分享计划-后台登陆</title>

    <link rel="icon" <%--type="image/png"--%> href="${pageContext.request.contextPath}/image/favicon.ico">
    <jsp:include page="${pageContext.request.contextPath}/WEB-INF/views/screen/admin/resource.jsp"/>

    <link rel="stylesheet" type="text/css" href="/css/login.css"></link>

</head>
<body class="loginbody">
<h1 style="margin-top:25px;color:#FFFFFF;text-align: center;">分享计划</h1>

<div class="loginbg">
    <div class="login_form">
        <p class="form_name">后台管理系统</p>
        <form id="loginForm" class="layui-form" action="/adminToLogin" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label"><i class="layui-icon" style="font-size: 20px; ">&#xe612;</i></label>
                <div class="layui-input-inline">
                    <input type="text" name="username" value="admin@qq.com" lay-verify="username" placeholder="请输入邮箱"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><i class="layui-icon" style="font-size: 20px;">&#xe622;</i></label>
                <div class="layui-input-inline">
                    <input type="password" name="password" value="654321" lay-verify="password" placeholder="请输入密码"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label"><i class="layui-icon" style="font-size: 20px;">&#xe63b;</i></label>
                    <div class="layui-input-inline">
                        <input type="text" name="verifyCode" lay-verify="verifyCode" placeholder="验证码"
                               autocomplete="off" class="layui-input"
                               style="width: 80px;float: left">
                        <img src="/kaptcha" id="kaptchaImage" title="看不清，点击换一张" onclick="changeVerifyCode()"
                             style="float: left;padding-left: 10px">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">记住我</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="rememberMe" lay-skin="switch" lay-text="ON|OFF" checked>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="loginSubmit" style="width: 190px">登陆</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">
    <%--var errorInfo = "${errorInfo}"--%>

    layui.use(['form'], function () {
        var form = layui.form;

        form.verify({
            username: function (value, item) {
                if (value == "") {
                    return '用户名不能为空';
                }
            }
            , password: function (value, item) {
                if (value == "") {
                    return '密码不能为空';
                }
            }, verifyCode: function (value, item) {
                if (value == "") {
                    return '验证码不能为空';
                }
            }
        });
        //监听提交
        form.on('submit(loginSubmit)', function (data) {
            var index = layer.load();
            $("#loginForm").ajaxSubmit({
                type: 'POST',
                success: function (result) {
                    layer.close(index);
                    changeVerifyCode();
                    if (result.success == true) {
                        window.location = "/admin/main";
                    } else {
                        layer.msg(result.msg, {
                            icon: 5,
                            offset: '150px',
                            time: 2000
                        });
                    }
                },
            });
            return false;
        });
//        if (errorInfo != "") {
//
//        }
    });

    /*刷新验证码*/
    function changeVerifyCode() {
        var time = new Date().getTime();
        $("#kaptchaImage").attr("src", "/kaptcha?time=" + time) //为了不让验证码缓存，为了安全起见，需要次次都刷新
    }

</script>
</html>